﻿@model List<BenzInfo.Hockey.Grenadiers.Models.Post>
           
@{
    ViewBag.Title = BenzInfo.Hockey.Grenadiers.Resources.Dictionary.HomePage;
}

<script type="text/javascript">

    $(document).ready(function () {

        DisplayNews('0');

        $('#dialog_Edit').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: 'Submit',
                    click: function () {
                        $('form', this).submit();
                    }
                },
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });

        $('#btn_edit_hotnews a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';

            $('#dialog_btn_save span').html('Submit');

            $('#dialog_Edit').empty().load(url, function () {
                $('#dialog_Edit').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_edit_homenews a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';

            $('#dialog_btn_save span').html('Submit');

            $('#dialog_Edit').empty().load(url, function () {
                $('#dialog_Edit').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_edit_newsletter a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.SubscribeNewsletter';

            $('#dialog_btn_save span').html('Submit');

            $('#dialog_Edit').empty().load(url, function () {
                $('#dialog_Edit').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_edit_newsletter_recipient a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.UpdateNewsletterRecipient';

            $('#dialog_btn_save span').html('Submit');

            $('#dialog_Edit').empty().load(url, function () {
                $('#dialog_Edit').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_edit_survey a').click(function () {
            var url = $(this).attr('href');
            var title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.EditQuestion';

            $('#dialog_btn_save span').html('Submit');

            $('#dialog_Edit').empty().load(url, function () {
                $('#dialog_Edit').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
        $('#btn_submit_survey').click(function () {
            var selected = $('input[name="radsurvey"]:checked').val()
            $.ajax(
            {
                type: "POST",
                url: "Home/SubmitSurvey",
                data: "optionSelected=" + selected,
                success: function (result) {
                    if (result.success) $("#survey input").prop("checked", false); // clear all the input fields on success
                    alert(result.message);
                },
                error: function (req, status, error) {
                    alert("@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.NotAnswerSurvey");
                }
            });
            return false;
        });
        if ("@(ViewBag.Ads != null)" == "True" && "@(ViewBag.Ads.Count > 0)" == "True") {
            $("#carouselAds").rcarousel({
                auto: {
                    enabled: true,
                    interval: 2000
                },
                width: 384,
                height: 180,
                margin: 0,
                visible: 1,
                step: 1
            });
        }
    });

    function DisplayNews(index) {

        $('.HomeNews').hide();
        $('.ActionHomeNews').hide();

        $('#News' + index).show();
        $('#Action' + index).show();
        }


</script>

<div id="dialog_Edit"></div>

<div id="hotnews">

@{
    var displayText = (ViewBag.Lang == "fr") ? ViewBag.HotNews.ContentFR : ViewBag.HotNews.ContentEN;
    if (ViewBag.HotNews.Link != null)
    {
        <a href="@ViewBag.HotNews.Link" target="_blank">
            <marquee>@displayText</marquee>
        </a>
    }
    else
    {
        <marquee>@displayText</marquee>
    }
}
</div>

@if (ViewBag.CurrentUser != null)
{
    <div id="HotNewsAdminActions">
        <p>
            <span id="btn_edit_hotnews">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Models.HotNews.AddHotNews, "EditHotNews", "Home")</span>
        </p>
    </div>
}

<div id="content">
    @if (Model != null)
    {
        int MaxCar = 24;
        <br />
        <div style="text-align:center">
        @if (Model.Count() > 0)
        {
            var text = (ViewBag.Lang == "fr") ? Model[0].TitleFR : Model[0].TitleEN;
            var textToDisplay = text;

            if (textToDisplay.Length > MaxCar)
            {
                textToDisplay = textToDisplay.Substring(0, MaxCar) + "...";
            }
            
            <p href="#" class="btnNavNews" onclick="DisplayNews('0')" title="@text">@textToDisplay</p>
        }
        @if (Model.Count() > 1)
        {
            var text = (ViewBag.Lang == "fr") ? Model[1].TitleFR : Model[1].TitleEN;
            var textToDisplay = text;

            if (textToDisplay.Length > MaxCar)
            {
                textToDisplay = textToDisplay.Substring(0, MaxCar) + "...";
            }
            
            <p href="#" class="btnNavNews" onclick="DisplayNews('1')" title="@text">@textToDisplay</p>
        }
        @if (Model.Count() > 2)
        {
            var text = (ViewBag.Lang == "fr") ? Model[2].TitleFR : Model[2].TitleEN;
            var textToDisplay = text;

            if (textToDisplay.Length > MaxCar)
            {
                textToDisplay = textToDisplay.Substring(0, MaxCar) + "...";
            }
            
            <p href="#" class="btnNavNews" onclick="DisplayNews('2')" title="@text">@textToDisplay</p>
        }
        @if (Model.Count() > 3)
        {
            var text = (ViewBag.Lang == "fr") ? Model[3].TitleFR : Model[3].TitleEN;
            var textToDisplay = text;

            if (textToDisplay.Length > MaxCar)
            {
                textToDisplay = textToDisplay.Substring(0, MaxCar) + "...";
            }
            
            <p href="#" class="btnNavNews" onclick="DisplayNews('3')" title="@text">@textToDisplay</p>
        }
        @if (Model.Count() > 4)
        {
            var text = (ViewBag.Lang == "fr") ? Model[4].TitleFR : Model[4].TitleEN;
            var textToDisplay = text;

            if (textToDisplay.Length > MaxCar)
            {
                textToDisplay = textToDisplay.Substring(0, MaxCar) + "...";
            }
            
            <p href="#" class="btnNavNews" onclick="DisplayNews('4')" title="@text">@textToDisplay</p>
        }
        </div>
        <br />
        
        if (ViewBag.CurrentUser != null)
        {
            <span id="btn_edit_homenews">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.AddHomeNews, "AddHomeNews", "Home")</span>
        
            for (int index = 0; index < Model.Count(); index++)
            {
                <div id="@("Action" + @index)" class="ActionHomeNews">
                    <p>
                        <span id="btn_edit_homenews">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit, "EditHomeNews", new { id = @Model[index].Id })</span>
                        | 
                        @Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete, "DeleteHomeNews", new { id = @Model[index].Id }, new { onclick = "return confirm('Delete?')" })
                    </p>
                </div>
            }
        }
        
        <div id="news">
            @for (int index = 0; index < Model.Count(); index++)
            {
                <div id="@("News" + @index)" class="HomeNews">
                    <input id=@("ID" + @index) type="hidden" value="@Model[index].Id" />
                    <h1 style="text-align:center">@(ViewBag.Lang == "fr" ? Model[index].TitleFR : Model[index].TitleEN)</h1>

                    <p>@Model[index].DateModified.ToString("yyyy-MM-dd HH:mm")</p>
                    <div class="wrap-box">
                    @if (Model[index].Picture != null)
                    {
                        <img src="@Url.Content("~/Utils/ImageHandler.ashx?src=posts/" + Model[index].Picture + "&maxwidth=250&maxheight=500")" alt="@(ViewBag.Lang == "fr" ? Model[index].TitleFR : Model[index].TitleEN)" />
                    }
                    @Html.Raw(ViewBag.Lang == "fr" ? Model[index].ContentFR.ToString().Replace("\n", "<br />") : Model[index].ContentEN.ToString().Replace("\n", "<br />"))
                	</div>
                </div>
            }
        </div>
    }
</div>


<div id="sidebar">
    @if (ViewBag.NextGame != null)
    {
        <div id="nextgame">
            <span class="lbl lbl_nextgame"></span>
             <a href="#" class="away" style="background-image: url(@Url.Content("~/Utils/ImageHandler.ashx?src=logos/" + ViewBag.NextGame.AwayTeam.Logo + "&maxwidth=75&maxheight=75"));background-repeat:no-repeat; background-position:center;"></a>
            <a href="#" class="home" style="background-image: url(@Url.Content("~/Utils/ImageHandler.ashx?src=logos/" + ViewBag.NextGame.HomeTeam.Logo + "&maxwidth=75&maxheight=75"));background-repeat:no-repeat; background-position:center;"></a>
            <span class="date">@ViewBag.NextGame.DateStart.ToString("yyyy-MM-dd HH:mm")</span>
        </div>
    }
    
    @if (ViewBag.LastGame != null)
    {
        <div id="lastgame">
            <span class="lbl lbl_lastgame"></span>
            <a href="#" class="away" style="background-image: url(@Url.Content("~/Utils/ImageHandler.ashx?src=logos/" + ViewBag.LastGame.AwayTeam.Logo + "&maxwidth=75&maxheight=75"));background-repeat:no-repeat; background-position:center;"></a>     
            <a href="#" class="home" style="background-image: url(@Url.Content("~/Utils/ImageHandler.ashx?src=logos/" + ViewBag.LastGame.HomeTeam.Logo + "&maxwidth=75&maxheight=75"));background-repeat:no-repeat; background-position:center;"></a>
            <span class="scoreaway">@ViewBag.LastGame.AwayScore</span>
            <span class="scorehome">@ViewBag.LastGame.HomeScore</span>
        </div>
    }    
    <!--DIFFUSION WEB-->    
    <div id="webdiffusion">
        <a href="@Url.Action("Index", "WebDiffusion")" id="lnk_webdiffusion"></a>
    </div>
    <!--ABONNEMENT À L'INFOLETTRE-->    
    <div id="newsletter">
        @if (ViewBag.CurrentUser != null)
        {
            <span id="btn_edit_newsletter_recipient">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Models.NewsletterIncsription.DisplayEmailToSendTo, "ChangeEmailRecipient", "Home")</span>
        }
            <span id="btn_edit_newsletter"><a href="@Url.Action("AddNewsletterInscription", "Home")" id="lnk_newsletter"></a></span>
    </div>
    <!--SONDAGE-->
    @if (ViewBag.CurrentUser != null)
    {
        <span id="btn_edit_survey">@Html.ActionLink(BenzInfo.Hockey.Grenadiers.Resources.Dictionary.EditQuestion, "Edit", "Survey")</span>
    }
    @if (ViewBag.Survey != null)
    {
        if ((ViewBag.Survey.Option1EN != "" && ViewBag.Survey.Option1EN != null && ViewBag.Lang != "fr") || (ViewBag.Survey.Option1FR != "" && ViewBag.Survey.Option1FR != null && ViewBag.Lang == "fr"))
        { 
            <div id="survey">
                @if (ViewBag.Lang == "fr")
                {
                    <div id="question">@(ViewBag.Survey.TitleFR)</div>
                    if (ViewBag.Survey.Option1FR != "" && ViewBag.Survey.Option1FR != null)
                    {
                        <div class="surveyoption"><input type="radio" value="1" name="radsurvey" /> @ViewBag.Survey.Option1FR</div>
                    }
                    if (ViewBag.Survey.Option2FR != "" && ViewBag.Survey.Option2FR != null)
                    {
                        <div class="surveyoption"><input type="radio" value="2" name="radsurvey" /> @ViewBag.Survey.Option2FR</div>
                    }
                    if (ViewBag.Survey.Option3FR != "" && ViewBag.Survey.Option3FR != null)
                    {
                        <div class="surveyoption"><input type="radio" value="3" name="radsurvey" /> @ViewBag.Survey.Option3FR</div>
                    }
                    if (ViewBag.Survey.Option4FR != "" && ViewBag.Survey.Option4FR != null)
                    {
                        <div class="surveyoption"><input type="radio" value="4" name="radsurvey" /> @ViewBag.Survey.Option4FR</div>
                    }
                }
                else
                {
                    <div>@(ViewBag.Survey.TitleEN)</div>
                    if (ViewBag.Survey.Option1EN != "" && ViewBag.Survey.Option1FR != null)
                    {
                        <div class="surveyoption"><input type="radio" value="1" name="radsurvey" /> @ViewBag.Survey.Option1EN</div>
                    }
                    if (ViewBag.Survey.Option2EN != "" && ViewBag.Survey.Option2EN != null)
                    {
                        <div class="surveyoption"><input type="radio" value="2" name="radsurvey" /> @ViewBag.Survey.Option2EN</div>
                    }
                    if (ViewBag.Survey.Option3EN != "" && ViewBag.Survey.Option3EN != null)
                    {
                        <div class="surveyoption"><input type="radio" value="3" name="radsurvey" /> @ViewBag.Survey.Option3EN</div>
                    }
                    if (ViewBag.Survey.Option4EN != "" && ViewBag.Survey.Option4EN != null)
                    {
                        <div class="surveyoption"><input type="radio" value="4" name="radsurvey" /> @ViewBag.Survey.Option4EN</div>
                    }
                }  
                <a id="btn_submit_survey" class="btnNavNews" title="@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Submit">@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Submit</a>  
            </div>  
        }
    }
    <!--COUPE AAA-->
    <div id="coupeAAA">
        <!--<a target="_blank" href="http://www.liguemidgetaaa.ca/index.php?option=com_content&view=article&id=474&Itemid=546" id="lnk_coupeAAA"></a>-->
        <iframe width="360" height="180" src="http://www.youtube.com/watch?v=oj-mqxEOAj4" frameborder="0" allowfullscreen></iframe>
    </div>
    <!--COUPE L'EXCELLENCE-->
    <div id="tapis">
        <a href="@Url.Action("Index", "ExcellenceCup")" id="lnk_tapis"></a>
    </div>

    <!--PARTENAIRES MEDIAS-->
    <div id="media">
        <a id="lnk_firstad"></a>
        <a target="_blank" href="http://www.chateauguayexpress.ca/Sports/Grenadiers-de-Chateauguay-24933" id="lnk_secondad"></a>
    </div> 

    <!--PUBLICITÉS-->
    <div id="ads">
		<div id="carouselAds">
            @if (ViewBag.Ads != null)
            {
                foreach (var item in ViewBag.Ads)
                {
                    if (item.Link != null)
                    {
                        <a target="_blank" href="@(item.Link)" title="@(ViewBag.Lang == "fr" ? item.TitleFR : item.TitleEN)" class="ads" style="background:url(@Url.Content("~/Utils/ImageHandler.ashx?src=posts/" + item.Picture + "&maxwidth=384&maxheight=384")) no-repeat center;"></a>;
                    }
                    else {
                        <a title="@(ViewBag.Lang == "fr" ? item.TitleFR : item.TitleEN)" class="ads" style="background:url(@Url.Content("~/Utils/ImageHandler.ashx?src=posts/" + item.Picture + "&maxwidth=384&maxheight=384")) no-repeat center;"></a>;
                    }
                    
                                                                                                                                                                                                                                                                                           }
            }
        </div>
    </div> 
</div>

<div style="clear:both;"></div>